<?php
// registers the buttons for use
function complete_register_friendly_buttons($buttons) {
	// inserts a separator between existing buttons and our new one
	// "friendly_button" is the ID of our button
	array_push($buttons, "button", "box", "highlight", "contact");
	return $buttons;
}

// filters the tinyMCE buttons and adds our custom buttons
function complete_friendly_shortcode_buttons() {
	// Don't bother doing this stuff if the current user lacks permissions
	if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') )
		return;
	 
	// Add only in Rich Editor mode
	if ( get_user_option('rich_editing') == 'true') {
		// filter the tinyMCE buttons and add our own
		add_filter("mce_external_plugins", "complete_add_friendly_tinymce_plugin");
		add_filter('mce_buttons', 'complete_register_friendly_buttons');
	}
}
// init process for button control
add_action('init', 'complete_friendly_shortcode_buttons');

// add the button to the tinyMCE bar
function complete_add_friendly_tinymce_plugin($plugin_array) {
	$plugin_array['button'] = get_bloginfo('stylesheet_directory') . '/functions/shortcodes/button-popup.js';
	$plugin_array['box'] = get_bloginfo('stylesheet_directory') . '/functions/shortcodes/box-popup.js';
	$plugin_array['highlight'] = get_bloginfo('stylesheet_directory') . '/functions/shortcodes/highlight-popup.js';
	$plugin_array['contact'] = get_bloginfo('stylesheet_directory') . '/functions/shortcodes/contact-popup.js';
	return $plugin_array;
}
?>